<%@ include file="srsAccessRight.jsp" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<jsp:useBean id="srscalendar" scope="page" class="srsService.srsCalendar"/>
<jsp:useBean id="srsmath" scope="page" class="srsService.srsMath"/>
<jsp:useBean id="srsUtilily" scope="request" class="srsService.srsUtil"/>
<jsp:useBean id="pool" scope="application" class="srsService.PoolConnBean" />

<TITLE>CALENDAR</TITLE>
<LINK rel='stylesheet' type='text/css' href='srsstyle.css'/>
<% 
  String realpath = request.getRequestURI();
  int hh = realpath.indexOf("/",2);
  String app = realpath.substring(1,hh);
%>
<script language=javascript>
<!--
function newin(V){

  l = "http://"+location.host+"/"+"<%=app%>"+"/"+V;
window.open(l,"calendar", "menubar=no,width=350,height=200,scrollbars=no,toolbar=no,status=no,resizable=no");
  //win2.creator=self
}
//-->
</script>

<%

  try{
    
    int rollforward = srsmath.Int(request.getParameter("ROLL"));

    srscalendar.setids(8 * 60 * 60 * 1000);
    srscalendar.setTimeZone(8 * 60 * 60 * 1000);
    srscalendar.setCurrentTime();

    int today = srscalendar.getYEAR() * 100 + srscalendar.getDAY_OF_YEAR();
    int cmonth = srscalendar.getMONTH();

    //SET 1ST DAY OF THE MONTH
    //GET 1ST WEEK NO.
    //GET 1ST OF THE WEEK NO.
    //START TO DRAW THE CALENDAR. (FIRST WEEK [LINE]) FOR EVERY 7 DAYS - (A)
    //WHILE THE NEXT SUNDAY IS BELONGS TO THE CURRENT MONTH DO (A)

    srscalendar.setDAY_OF_MONTH(1);

    srscalendar.setMONTH(srscalendar.getMONTH() + rollforward);
    int working_month = srscalendar.getMONTH();

    out.println("<TABLE border=1><TR>");
    out.println("<TH COLSPAN=99>" + (srscalendar.getMONTH_FULL()) + " " + srscalendar.getYEAR() );
    out.println("<TR><TH >YEAR");
    out.println("<TH >WEEK");
    out.println("<TH ><font color=red>S</font>");
    out.println("<TH >M");
    out.println("<TH >T");
    out.println("<TH >W");
    out.println("<TH >T");
    out.println("<TH >F");
    out.println("<TH >S");

    while( srscalendar.getDAY_OF_WEEK() > 1 ) {
      srscalendar.moveFORWARD(-1);
    }

    do {
      if( srscalendar.getWEEK_OF_YEAR() == 1 && srscalendar.getDAY_OF_YEAR() != 1 ) {
        out.print("<TR><TD>" + (srscalendar.getYEAR() + 1) );
      }
      else {
        out.print("<TR><TD>" + srscalendar.getYEAR() );
      }
      out.print("<TD>" + srscalendar.getWEEK_OF_YEAR() );

      for(int i=0; i<7; i++) {
        if(srscalendar.getYEAR() * 100 + srscalendar.getDAY_OF_YEAR() == today) {
          out.println("<TD><FONT COLOR=BLACK>" + srscalendar.getDAY_OF_MONTH() + "</FONT>");
        }
        else {
          out.print("<TD><FONT COLOR=BLUE>" + srscalendar.getDAY_OF_MONTH() + "</FONT>");
        }
        srscalendar.moveFORWARD(1);
      }
    } while( srscalendar.getMONTH() == working_month );

    out.println("<TFOOT><TH COLSPAN=99>");
    out.println("<A HREF=Calendar.jsp?ROLL=" +(rollforward-1)+ ">PREV</A>");
    out.println("<A HREF=Calendar.jsp?ROLL=" +(0)+ ">NOW</A>");
    out.println("<A HREF=Calendar.jsp?ROLL=" +(rollforward+1)+ ">NEXT</A>");
    out.println("</TFOOT>");
    out.println("</TABLE>");
    
  }
  catch(Exception e) {
    out.println("<TABLE><TR>");
    out.println("<TH>Calendar Error = " + e.toString() );
    out.println("</TABLE>");
  }

%>
